package com.wwmz.pattern.singleton.register;

import com.wwmz.pattern.singleton.destroy.SeriableSingleton;

import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.ObjectInputStream;
import java.io.ObjectOutputStream;
import java.lang.reflect.Constructor;

/**
 * Created by wumz on 2020/9/17 14:39
 */
public class EnumTest {

    public static void main(String[] args) {
        //把singleton2值赋给singleton1
//        SeriableSingleton singleton1 = null;
//        SeriableSingleton singleton2 = SeriableSingleton.getInstance();
//        try {
//            FileOutputStream out = new FileOutputStream("SeriableSingleton.obj");
//            ObjectOutputStream objectOutputStream = new ObjectOutputStream(out);
//            objectOutputStream.writeObject(singleton2);
//            objectOutputStream.flush();
//            objectOutputStream.close();
//
//            FileInputStream in = new FileInputStream("SeriableSingleton.obj");
//            ObjectInputStream objectInputStream = new ObjectInputStream(in);
//            singleton1 = (SeriableSingleton)objectInputStream.readObject();
//            objectInputStream.close();
//
//            System.out.println(singleton1);
//            System.out.println(singleton2);
//            System.out.println(singleton2 == singleton1);
//        }catch (Exception e){
//            e.printStackTrace();
//        }
        try {

            Class clazz = EnumSingleton.class;
            Constructor declaredConstructor = clazz.getDeclaredConstructor(String.class, int.class);
            declaredConstructor.setAccessible(true);
            EnumSingleton enumSingleton = (EnumSingleton)declaredConstructor.newInstance("wumz", 123);
        }catch (Exception e){
            e.printStackTrace();
        }
    }
}
